/*
 * @Author: silence
 * @Date: 2022-07-21 14:14:50
 * @LastEditors: silence silence9685@163.com
 * @LastEditTime: 2023-07-26 16:10:53
 * @Description: 设置当前app：页面加载状态组件
 */
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/src/smart_refresher.dart';
import 'package:sil_base_widget_package/sil_base_widget_package.dart';

import '../../../utils/eventBus/eventBus.dart';
import '../../../utils/string/StringConstant.dart';
import '../../main.dart';
import '../../pages/Mine/Language/SilLocalizations/SilLocalizations.dart';
import '../../utils/color/ColorUtils.dart';

mixin FutureBuilderInterfaceInstance implements SilFutureBuilderInterface {
  @override
  Widget loadingWidget() {
    String? promptTitle = LangOf(navigatorKey.currentState!.context)?.common?.loading;
    return SilPageLoadingWidget(indicatorColor: ColorUtils.color_theme,promptTitle:promptTitle);
  }

  @override
  Widget netErrorWidget(
      {RefreshController? errorRefreshController,
      void Function()? reloadFunc}) {
    // 有网时，进行自动刷新
    bus.on(StringConstant.NetStateChange, (network) {
      if (network) {
        if (errorRefreshController != null) {
          errorRefreshController.requestRefresh();
        }
      }
    });

    String? regainPrompt =
        LangOf(navigatorKey.currentState!.context)?.common?.regain;

    String? prompt =
        LangOf(navigatorKey.currentState!.context)?.netErr?.net_err;

    return SilNetErrorWidget(
        backgroundColor: ColorUtils.color_bg,
        promptTextStyle:
            TextStyle(fontSize: 14, color: ColorUtils.color_font_main),
        textStyle: TextStyle(fontSize: 14, color: ColorUtils.color_theme),
        promptMargin: EdgeInsets.only(top: 10),
        buttonMargin: EdgeInsets.only(top: 10),
        refreshController: errorRefreshController,
        reloadFunc: reloadFunc,
        bottomButtonTitle: regainPrompt, //"点击屏幕重试",
        prompt: prompt //'网络不给力'
        );
  }

  @override
  Widget noDataWidget(
      {RefreshController? emptyRefreshController,
      void Function()? reloadFunc}) {
    // return SilEmptyDataWidget(
    //     refreshController: emptyRefreshController, reloadFunc: reloadFunc);
    String? prompt =
        LangOf(navigatorKey.currentState!.context)?.faultList?.no_data;

    return Container(
        alignment: Alignment.center,
        child:
            SilText(prompt, fontSize: 14.w, color: ColorUtils.color_subtitle));
  }
}
